<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
    <!ENTITY copy "&#169;">
    <!ENTITY nbsp "&#160;">
    <!ENTITY laquo "&#171;">
    <!ENTITY raquo "&#187;">
]>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">
  
  <xsl:output encoding="UTF-8"
              method="xml"
              omit-xml-declaration="yes"
              indent="no"
              doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>  

  <xsl:variable name="Root" select="/page/settings/url" />
  <xsl:variable name="Files" select="/page/settings/files_url" />
  <xsl:variable name="Images" select="/page/settings/images_url" />
  <xsl:variable name="Settings" select="/page/settings" />
  <xsl:variable name="Controller" select="/page/settings/controller" />
  <xsl:variable name="This" select="/page/settings/this" />
  <xsl:variable name="Main" select="/page/content/Main" />
  <xsl:variable name="User" select="/page/content/auth-info" />
  <xsl:variable name="Content" select="/page/content" />
  <xsl:variable name="Cats" select="/page/content/Cats" />
  <xsl:variable name="Form" select="/page/content/Main/form" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="page">
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>
          <xsl:value-of select="$Settings/title"/>
        </title>
        <!--212.26.144.104:1204-->
        <script type="text/javascript" src="js/tiny_mce/tiny_mce_popup.js"></script>
        <script type="text/javascript" src="2js/objects_plugin/dialog.js"></script>


        <script type="text/javascript" src="js/jq.js"></script>
        <script type="text/javascript" src="js/objects_plugin/objects_plugin.js"></script>
        

        <link href="js/objects_plugin/images_plugin.css" rel="stylesheet" type="text/css" />
        <link href="css/ArtPager.css" rel="stylesheet" type="text/css" />
      </head>
      <body>
        <div id="gallery">
          <xsl:for-each select="$Main/data/data/row">            
            <div class="photo">
              <a href="#">
                <img src="{$Files}{path}{id}square_small{file_name}" rel="{$Files}{path}{id}original{file_name}" title="{title}"/>
              </a>              
            </div>
          </xsl:for-each>           
        </div>
        <br class="spacer"/>
        <div class="pages">
          <xsl:call-template name="pager1">
            <xsl:with-param name="node" select="$Main/data/pager"></xsl:with-param>
          </xsl:call-template>
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="pager1">
    <xsl:param name="node"></xsl:param>

    <xsl:variable name="sort" select="/page/content/main/@sort" />
    <xsl:variable name="family" select="/page/content/main/@family" />
    <xsl:variable name="fromTopic" select="/page/content/main/@fromTopic" />

    <!-- page left -->
    <div class="fclr"></div>

    <xsl:if test="number($node/page_count) &gt; 1">

      <div class="ArtPager">

        <div class="pageLeft"></div>
        <a href="#" class="pageCenter">
          <xsl:choose>
            <xsl:when test="number($node/current_page) &gt; 1">
              <xsl:attribute name="href">
                <xsl:text>?page=</xsl:text>
                <xsl:value-of select="number($node/current_page) - 1"/>

                <xsl:if test="string-length($sort) &gt; 0">
                  <xsl:text>&amp;sort=</xsl:text>
                  <xsl:value-of select="$sort"/>
                </xsl:if>

                <xsl:if test="string-length($family) &gt; 0">
                  <xsl:text>&amp;family=</xsl:text>
                  <xsl:value-of select="$family"/>
                </xsl:if>

                <xsl:if test="string-length($fromTopic) &gt; 0">
                  <xsl:text>&amp;fromTopic=</xsl:text>
                  <xsl:value-of select="$fromTopic"/>
                </xsl:if>


              </xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="style">
                cursor:default;
              </xsl:attribute>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text> </xsl:text>
          <img src="{$Images}/pagerleft.gif" alt="" border="0" style="position:relative; top:4px;" />
        </a>
        <div class="pageRight"></div>



        <xsl:call-template name="pager1.counter">
          <xsl:with-param name="i" select="$node/start_page"></xsl:with-param>
          <xsl:with-param name="node" select="$node"></xsl:with-param>
        </xsl:call-template>


        <span class="innerText2"> из </span>

        <div class="pageLeft"></div>
        <a href="?page={$node/last_page}" class="pageCenter">

          <xsl:if test="string-length($sort) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$node/last_page"/>
              <xsl:text>&amp;sort=</xsl:text>
              <xsl:value-of select="$sort"/>
            </xsl:attribute>
          </xsl:if>

          <xsl:if test="string-length($family) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$node/last_page"/>
              <xsl:text>&amp;family=</xsl:text>
              <xsl:value-of select="$family"/>
            </xsl:attribute>
          </xsl:if>


          <xsl:if test="string-length($fromTopic) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$node/last_page"/>
              <xsl:text>&amp;fromTopic=</xsl:text>
              <xsl:value-of select="$fromTopic"/>
            </xsl:attribute>
          </xsl:if>


          <xsl:value-of select="$node/last_page"/>
        </a>
        <div class="pageRight"></div>

        <div class="pageLeft"></div>
        <a href="#" class="pageCenter">
          <xsl:choose>
            <xsl:when test="number($node/current_page) &lt; number($node/last_page)">
              <xsl:attribute name="href">
                <xsl:text>?page=</xsl:text>
                <xsl:value-of select="number($node/current_page) + 1"/>


                <xsl:if test="string-length($sort) &gt; 0">
                  <xsl:text>&amp;sort=</xsl:text>
                  <xsl:value-of select="$sort"/>
                </xsl:if>

                <xsl:if test="string-length($family) &gt; 0">
                  <xsl:text>&amp;family=</xsl:text>
                  <xsl:value-of select="$family"/>
                </xsl:if>


                <xsl:if test="string-length($fromTopic) &gt; 0">
                  <xsl:text>&amp;fromTopic=</xsl:text>
                  <xsl:value-of select="$fromTopic"/>
                </xsl:if>

              </xsl:attribute>
            </xsl:when>
          </xsl:choose>
          <img src="{$Images}/pagerright.gif" alt="" border="0" style="position:relative; top:4px;"/>
          <xsl:text> </xsl:text>
        </a>
        <div class="pageRight"></div>

        <div class="fclr"></div>
      </div>
      <!-- pager right -->
    </xsl:if>
  </xsl:template>

  <xsl:template name="pager1.counter">
    <xsl:param name="i"></xsl:param>
    <xsl:param name="node"></xsl:param>

    <xsl:variable name="sort" select="/page/content/main/@sort" />
    <xsl:variable name="family" select="/page/content/main/@family" />
    <xsl:variable name="fromTopic" select="/page/content/main/@fromTopic" />

    <xsl:choose>
      <xsl:when test="number($node/current_page) = number($i)">
        <div class="pageLeftActive"></div>
        <a  href="#" class="pageCenterActive" style="cursor:default;">
          <xsl:value-of select="$i"/>
        </a>
        <div class="pageRightActive"></div>
      </xsl:when>
      <xsl:otherwise>
        <!-- show -> -->
        <div class="pageLeft"></div>
        <a href="?page={$i}" class="pageCenter">

          <xsl:if test="string-length($sort) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$i"/>
              <xsl:text>&amp;sort=</xsl:text>
              <xsl:value-of select="$sort"/>
            </xsl:attribute>
          </xsl:if>

          <xsl:if test="(string-length($family) &gt; 0) or (string-length($fromTopic) &gt; 0)">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$i"/>
              <xsl:text>&amp;family=</xsl:text>
              <xsl:value-of select="$family"/>
              <xsl:text>&amp;fromTopic=</xsl:text>
              <xsl:value-of select="$fromTopic"/>
            </xsl:attribute>
          </xsl:if>


          <!--xsl:if test="string-length($fromTopic) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$i"/>
              <xsl:text>&amp;fromTopic=</xsl:text>
              <xsl:value-of select="$fromTopic"/>
            </xsl:attribute>
          </xsl:if -->


          <xsl:value-of select="$i"/>
        </a>
        <div class="pageRight"></div>
      </xsl:otherwise>
    </xsl:choose>


    <!-- test -> -->

    <xsl:if test="(number($i) &lt; (number($node/start_page)+4)) and number($i) &lt; (number($node/last_page)) ">
      <xsl:call-template name="pager1.counter">
        <xsl:with-param name="i" select="$i+1"></xsl:with-param>
        <xsl:with-param name="node" select="$node"></xsl:with-param>
      </xsl:call-template>
    </xsl:if>

  </xsl:template>  
  
</xsl:stylesheet>